<template>
  <div class="zjylistpage-page">
    <van-pull-refresh
        :disabled="refreshDisabled"
        @refresh="onRefresh"
        v-model="isRefresh"
        loosing-text="释放即可刷新"
        pulling-text="下拉刷新">
      <!--      区域开始-->
      <div class="zjylistpage-list" v-if="'quyu' == props.currentTab||'search-quyu' == props.currentTab"
           @scroll="handleScroll($event)">
        <div class="zjylistpage-lsitHeader zjylistpage-list-item-width zjylistpage-lsitHeader-title-cloum1">
          <div class="zjylistpage-lsitHeader-title zjylistpage-list-item-div-cloum1">{{ listTitle.t1 }}</div>
          <div class="zjylistpage-lsitHeader-title">{{ listTitle.t2 }}</div>
          <div class="zjylistpage-lsitHeader-title">{{ listTitle.t3 }}</div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t4"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t5"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t6"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t7"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t8"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t9"></div>
        </div>
        <div class="zjylistpage-list-item zjylistpage-list-item-width" v-for="(item,index) in listData">
          <div class="zjylistpage-list-item-data">
            <div class="zjylistpage-list-item-div1  zjylistpage-list-item-div-cloum1 zjylistpage-list-item-div1"
                 @click="itemClick(item,cjRegion+1)">
              <img class="zjylistpage-list-item-div-img" :src="item.viewShow==0?icon1:icon2"
                   v-show="imgshow(item)">
              <div class="zjylistpage-list-item-div-div">
                {{ item.vd.t1 }}
              </div>
            </div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'qiye','企业销售情况')"
                  :style="'合计' == item.regionName?'color: none;':'color:#16CE8A ;'">{{ item.vd.t2 }}
            </div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'pz','品种销售情况')"
                 :style="'合计' == item.regionName?'color: none;':'color:#16CE8A ;'">{{ item.vd.t3 }}
            </div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'diaoyunliang','调运量情况')"
                 :style="'合计' == item.regionName?'color: none;':'color:#16CE8A ;'" v-html="item.vd.t4"></div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'beianzhexinxi','备案者信息')"
                 :style="'合计' == item.regionName?'color: none;':'color:#16CE8A ;'" v-html="item.vd.t5"></div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'mendiandaohuoliang','门店到货清况')"
                 :style="'合计' == item.regionName?'color: none;':'color:#16CE8A ;'" v-html="item.vd.t6"></div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'xiaoshouliang','销售清况')"
                 :style="'合计' == item.regionName?'color: none;':'color:#16CE8A ;'" v-html="item.vd.t7"></div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'zhongzhinonghushu','种植农户列表')"
                 :style="'合计' == item.regionName?'color: none;':'color:#16CE8A ;'" v-html="item.vd.t8"></div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t9"></div>
          </div>
          <div class="zjylistpage-list-line"></div>
          <Adapter :itemData="item" :itemClick="itemClick" :cjRegion="cjRegion+1" :qiyeshuClick="qiyeshuClick"/>
        </div>
      </div>
      <!--      区域结束-->
      <!--      企业品种开始-->
      <div class="zjylistpage-list" @scroll="handleScroll($event)"
           v-if="('qiye' == props.currentTab||'pz' == props.currentTab||'qiye-pz'==props.currentTab)&&cjRegion!=4">
        <div class="zjylistpage-lsitHeader zjylistpage-list-item-width2 zjylistpage-lsitHeader-title-cloum1">
          <div class="zjylistpage-lsitHeader-title zjylistpage-list-item-div-cloum1">{{ listTitle.t1 }}</div>
          <div class="zjylistpage-lsitHeader-title">{{ listTitle.t2 }}</div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t3"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t4"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t5"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t6"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t7"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t8"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t9"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t10"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t11"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t12"></div>

        </div>
        <div class="zjylistpage-list-item zjylistpage-list-item-width2" v-for="(item,index) in listData"
        >
          <div class="zjylistpage-list-item-data">
            <div class="zjylistpage-list-item-div1  zjylistpage-list-item-div-cloum1 zjylistpage-list-item-div1">
              <div class="zjylistpage-list-item-div-div">
                {{ item.vd.t1 }}
              </div>
            </div>
            <div class="zjylistpage-list-item-div"
                 @click="qiyeshuClick(item,'qiye' == props.currentTab?'qiye-pz':'pz-qiye','qiye' == props.currentTab?'品种销售情况':'企业销售情况')"
                 :style="'qiye' == props.currentTab?'color: #16CE8A;':'color: none;'">{{ item.vd.t2 }}
            </div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t3"></div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t4"></div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t5"></div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t6"></div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'qiye-diaoyunliang','调运量情况')"
                 style="color: #16CE8A;" v-html="item.vd.t7"></div>
            <div class="zjylistpage-list-item-div" @click="qiyeshuClick(item,'qiye-beianzhexinxi','备案者信息')"
                 style="color: #16CE8A;" v-html="item.vd.t8"></div>
            <div class="zjylistpage-list-item-div"
                 @click="qiyeshuClick(item,'qiye-mendiandaohuoliang','门店到货清况')"
                 style="color: #16CE8A;" v-html="item.vd.t9"></div>
            <div class="zjylistpage-list-item-div"
                 @click="qiyeshuClick(item,'qiye-xiaoshouliang','销售清况')"
                 style="color: #16CE8A;" v-html="item.vd.t10"></div>
            <div class="zjylistpage-list-item-div"
                 @click="qiyeshuClick(item,'qiye-zhongzhinonghushu','种植农户列表')"
                 style="color: #16CE8A;" v-html="item.vd.t11"></div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t12"></div>

          </div>
          <div class="zjylistpage-list-line"></div>
        </div>
      </div>
      <!--      企业结束-->
      <!--      县级开始-->
      <div class="zjylistpage-list" @scroll="handleScroll($event)"
           v-if="('qiye' == props.currentTab||'pz' == props.currentTab||'qiye-pz'==props.currentTab)&&cjRegion==4">
        <div class="zjylistpage-lsitHeader  zjylistpage-lsitHeader-title-cloum1 zjylistpage-list-item-width3">
          <div class="zjylistpage-lsitHeader-title zjylistpage-list-item-div-cloum1">{{ listTitle.t1 }}</div>
          <div class="zjylistpage-lsitHeader-title">{{ listTitle.t2 }}</div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t3"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t4"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t5"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t6"></div>
          <div class="zjylistpage-lsitHeader-title" v-html="listTitle.t7"></div>

        </div>
        <div class="zjylistpage-list-item zjylistpage-list-item-width3" v-for="(item,index) in listData">
          <div class="zjylistpage-list-item-data">
            <div class="zjylistpage-list-item-div1  zjylistpage-list-item-div-cloum1 zjylistpage-list-item-div1">
              <div class="zjylistpage-list-item-div-div">
                {{ item.vd.t1 }}
              </div>
            </div>
            <div class="zjylistpage-list-item-div">{{ item.vd.t2 }}</div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t3"></div>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t4"
                 @click="qiyeshuClick(item,'qiye-mendiandaohuoliang','门店数量')"
                 style="color: #16CE8A;"
            />

            <div class="zjylistpage-list-item-div" v-html="item.vd.t5"
                 @click="qiyeshuClick(item,'qiye-mendiandaohuoliang','门店到货清况')"
                 style="color: #16CE8A;"/>
            <div class="zjylistpage-list-item-div" v-html="item.vd.t6"
                 @click="qiyeshuClick(item,'qiye-xiaoshouliang','销售清况')"
                 style="color: #16CE8A;"/>
            <div class="zjylistpage-list-item-div"
                 @click="qiyeshuClick(item,'qiye-zhongzhinonghushu','种植农户列表')"
                 style="color: #16CE8A;" v-html="item.vd.t7"/>
          </div>
          <div class="zjylistpage-list-line"></div>
        </div>
      </div>
      <!--      县级结束-->
    </van-pull-refresh>
    <van-popup
        v-model:show="showBottomDialog"
        position="bottom"
        :style="{ height: '100%' }">
      <QiYeShuDialog v-if="dialogType=='qiye'
      ||dialogType=='pz'
      ||'qiye-pz'==dialogType"
                     :dilogShow="dilogShow"
                     :dialogData="dialogData"
                     :key="dialogKey"
                     :dialogTitle="dialogTitle"
                     :dialogPageType="dialogType"/>
      <DiaoyunlingDialog v-if="dialogType=='diaoyunliang'
      ||dialogType=='beianzhexinxi'
      ||dialogType=='mendiandaohuoliang'
      ||dialogType=='xiaoshouliang'
      ||dialogType=='zhongzhinonghushu'
||'qiye-diaoyunliang'==dialogType
||'qiye-beianzhexinxi'==dialogType
||'qiye-mendiandaohuoliang'==dialogType
||'qiye-xiaoshouliang'==dialogType
||'qiye-zhongzhinonghushu'==dialogType"
                         :dilogShow="dilogShow"
                         :dialogData="dialogData"
                         :dialogTitle="dialogTitle"
                         :dialogPageType="dialogType"
                         :user="user"
                         :key="dialogKey"/>
    </van-popup>
  </div>


</template>
<script setup>
import '@/views/zhuanjiyin/css/ZJYListPage.css'
import uiUtil from "@/util/UiUtil.js";
import Adapter from "@/components/ZJYListPage/ZjyListAdapter.vue"
import {reactive, onMounted, inject, ref, markRaw, provide} from "vue";
import icon1 from "@/assets/img/jiantou1.webp"
import icon2 from "@/assets/img/jiantou2.png"
import QiYeShuDialog from "@/views/zhuanjiyin/view/QiYeShuDialog.vue"
import DiaoyunlingDialog from "@/views/zhuanjiyin/view/DiaoyunlingDialog.vue"

///////////////列事件///////////////////
const showBottomDialog = ref(false)
const dialogType = ref('')
const dilogShow = () => {
  showBottomDialog.value = !showBottomDialog.value
  console.log('dilogShow=', showBottomDialog.value)
}
const dialogData = ref(null)
const dialogKey = ref(getRandomString(18))
const dialogTitle = ref('')
const qiyeshuClick = (item, type, title) => {
  if ('pz-qiye' == type) return
  // debugger
  dialogType.value = type
  dialogData.value = item
  dialogKey.value = getRandomString(18)
  dialogTitle.value = title
  console.log('type=', type, 'dialogKey=', dialogKey.value)
  dilogShow()
}

//////////////初始化//////////////////////////////////
var user = JSON.parse(localStorage.getItem(uiUtil.urlPath.keys.user))
const props = defineProps({
  currentTab: String,
  dialogPageData: Object,//弹出框数据
  searchQuyuDialogData: Object//搜索
});

onMounted(() => {
  console.log('user=', user)
  initviewdata()
})
const initviewdata = () => {
  getCjRegion()
  initTitle()
  param()
  // getList(null, 1)
  onRefresh()
}

uiUtil.watch(props.currentTab, (v1, v2) => {
  initTitle()
  // getList()
})
console.log('currentTab=', props.currentTab)
////////////表头解析///////////////////////////
const listTitle = uiUtil.ref({})
const initTitle = () => {

  if ('quyu' == props.currentTab || 'search-quyu' == props.currentTab) {
    listTitle.value = {
      t1: '区域',
      t2: '企业数',
      t3: '品种数',
      t4: '调运量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
      t5: '门店数量',
      t6: '门店到货量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
      t7: '销售量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
      t8: '种植农户',
      t9: '种植面积<br>' + (user.RegionName == '国家' ? '(万亩)' : '(亩)'),
    }
  } else if ('qiye' == props.currentTab || 'pz' == props.currentTab || 'qiye-pz' == props.currentTab) {

    if (3 == user.UserRoleID) {
      listTitle.value = {
        // t1: '企业',
        // t2: '品种数',
        t3: '调入量<br>(公斤)',
        t4: '门店数量',
        t5: '门店到货量<br>(公斤)',
        t6: '销售量<br>(公斤)',
        t7: '种植农户数',
        // t8: '种植面积<br>(亩)',
      }
      if ('qiye' == props.currentTab) {
        listTitle.value.t1 = '企业'
        listTitle.value.t2 = '品种数'
      } else if ('pz' == props.currentTab || 'qiye-pz' == props.currentTab) {
        listTitle.value.t1 = '品种'
        listTitle.value.t2 = '企业数'
      }
    } else {
      listTitle.value = {
        // t1: '企业',
        // t2: '品种数',
        t3: '种植面积<br>' + (user.RegionName == '国家' ? '(万亩)' : '(亩)'),
        t4: '收储量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
        t5: '加工量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
        t6: '包装量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
        t7: '调运量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
        t8: '门店数量',
        t9: '门店到货量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
        t10: '销售量<br>' + (user.RegionName == '国家' ? '(万公斤)' : '(公斤)'),
        t11: '种植农户数',
        t12: '种植面积<br>' + (user.RegionName == '国家' ? '(万亩)' : '(亩)'),
      }
      if ('qiye' == props.currentTab) {
        listTitle.value.t1 = '企业'
        listTitle.value.t2 = '品种数'
      } else if ('pz' == props.currentTab || 'qiye-pz' == props.currentTab) {
        listTitle.value.t1 = '品种'
        listTitle.value.t2 = '企业数'
      }
    }

  }
}

///////////////显示值解析//////////////////////////
function parsValue(item) {
  if ('quyu' == props.currentTab || 'search-quyu' == props.currentTab) {
    item.vd = {
      t1: item.regionName,
      t2: item.companyCount,//'企业数',
      t3: item.varietyCount,//'品种数',
      t4: getNumberData2(item.transportTotal),//'调运量<br>'+(user.RegionName=='国家'?'（万公斤）':'（公斤）'),
      t5: item.branchCount,//'门店数量',
      t6: getNumberData2(item.totalSeedQuantity),//,'门店到货量<br>'+(user.RegionName=='国家'?'(万公斤）':'（公斤）'),
      t7: getNumberData2(item.saleTotal),//'销售量<br>'+(user.RegionName=='国家'?'（万公斤）':'（公斤）'),
      t8: item.farmerTotal,//'种植农户',
      t9: getNumberData2(item.plantAreaTotal),//'种植面积<br>'+(user.RegionName=='国家'?'（万亩）':'（亩）'),
    }
  } else if ('qiye' == props.currentTab || 'pz' == props.currentTab || 'qiye-pz' == props.currentTab) {
    if (3 == user.UserRoleID) {
      item.vd = {
        // t1: item.companyName,
        // t2: item.varietyCount,
        t3: getNumberData2(item.transportTotal),// + '' + getNumberData2(item.transportInTotal),//'调ru量,
        t4: item.branchCount,//门店数量
        t5: getNumberData2(item.totalSeedQuantity),//门店到货量
        t6: getNumberData2(item.saleTotal),//销售量
        t7: item.farmerTotal,//种植农户数
        t8: getNumberData2(item.plantAreaTotal),//种植面积
      }
      if ('qiye' == props.currentTab) {
        item.vd.t1 = item.companyName
        item.vd.t2 = item.varietyCount
      } else if ('pz' == props.currentTab || 'qiye-pz' == props.currentTab) {
        item.vd.t1 = item.varietyName
        item.vd.t2 = '合计' == item.companyName ? item.companyCount : item.companyName
      }
    } else {
      item.vd = {
        // t1: item.companyName,
        // t2: item.varietyCount,
        t3: getNumberData2(item.seedAreaTotal),//制种面积
        t4: getNumberData2(item.purchaseTotal),//收储量
        t5: getNumberData2(item.produceTotal),//加工两
        t6: getNumberData2(item.packageTotal),//包装量
        t7: getNumberData2(item.transportTotal),//'调运量
        t8: item.branchCount,//门店数量
        t9: getNumberData2(item.totalSeedQuantity),//门店到货量
        t10: getNumberData2(item.saleTotal),//销售量
        t11: item.farmerTotal,//种植农户数
        t12: getNumberData2(item.plantAreaTotal),//种植面积
      }
      if ('qiye' == props.currentTab) {
        item.vd.t1 = item.companyName
        item.vd.t2 = item.varietyCount
      } else if ('pz' == props.currentTab || 'qiye-pz' == props.currentTab) {
        item.vd.t1 = item.varietyName
        item.vd.t2 = item.companyName
      }
    }

  }
}

//////////////点击下钻/////////////////////
const itemClick = (item, cj) => {
  // debugger
  if ("1" == user.UserRoleID && cj == 4) {//"国家"
    return
  } else if ("2" == user.UserRoleID && cj == 4) {// "省"
    return
  } else if ("3" == user.UserRoleID && cj == 4) {//"县"
    return
  } else if ("4" == user.UserRoleID && cj == 4) {//"市"
    return
  }
  // debugger
  if ('quyu' == props.currentTab||'search-quyu'==props.currentTab) {
    // map = {HashMap@18565}  size = 6
    // "totalFlag" -> "0"
    // "groupType" -> "4"
    // "varietyName" -> ""
    // "region" -> "130000"
    // "realCompanyName" -> ""
    // "crop" -> ""
    totalFlag.value = 0;
    groupType.value = 4
    region.value = item.regionCode
    // debugger
    if (uiUtil.isStrNull(item.viewShow) || 0 == item.viewShow) {
      item.viewShow = 1;
    } else {
      item.viewShow = 0;
    }
    if (uiUtil.isArrNull(item.arr)) {
      getList(item, cj)
    }
  }


}

function imgshow(item) {
  if (item.vd.t1 == '合计') return false
  if (cjRegion.value > 2) return false
  return true
}

//////////////请求//////////////////////
const param = () => {
  console.log('props.currentTab=', props.currentTab, 'props.dialogPageData', props.dialogPageData)
  if ('quyu' == props.currentTab || 'search-quyu' == props.currentTab) {
    // map = {HashMap@18565}  size = 6
    // "totalFlag" -> "0"
    // "groupType" -> "4"
    // "varietyName" -> ""
    // "region" -> "130000"
    // "realCompanyName" -> ""
    // "crop" -> ""
    totalFlag.value = 0;
    groupType.value = 4
    region.value = user.RegManageRegionID
    if ('search-quyu' == props.currentTab) {
      // debugger
      //http://114.242.25.97:20167/api/seedarchive/api/searchRegionByRegionName?
      // totalFlag=0&groupType=4&regionName=河北省&varietyName=&realCompanyName=&parentRegionCode=999999&crop=
      regionName.value = props.searchQuyuDialogData.entityName
    }

  } else if ('qiye' == props.currentTab) {
    // map = {HashMap@18663}  size = 6
    // "totalFlag" -> "1"
    // "groupType" -> "2"
    // "varietyName" -> ""
    // "region" -> "999999"
    // "realCompanyName" -> ""
    // "crop" -> ""
    totalFlag.value = 1;
    groupType.value = 2
    region.value = user.RegManageRegionID
    if (uiUtil.isNotNull(props.dialogPageData)) {
      // 区域-企业数
      // map = {HashMap@18629}  size = 6
      // "totalFlag" -> "1"
      // "groupType" -> "2"
      // "varietyName" -> ""
      // "region" -> "130000"
      // "realCompanyName" -> ""
      // "crop" -> ""
      // debugger
      region.value = props.dialogPageData.regionCode
      crop.value = props.dialogPageData.crop
    }
    if (cjRegion.value == 4) {
      //http://114.242.25.97:20167/api/seedarchive/api/getAllSeedCompanySummary?
      // totalFlag=1&groupType=3&varietyName=&region=130108&realCompanyName=&crop=
      groupType.value = 3
    }
  } else if ('pz' == props.currentTab || 'qiye-pz' == props.currentTab) {
    // map = {HashMap@18507}  size = 6
    // "totalFlag" -> "1"
    // "groupType" -> "3"
    // "varietyName" -> ""
    // "region" -> "999999"
    // "realCompanyName" -> ""
    // "crop" -> ""
    totalFlag.value = 1;
    groupType.value = 3
    region.value = user.RegManageRegionID
    if (uiUtil.isNotNull(props.dialogPageData)) { // 区域-品种数
      // map = {HashMap@18666}  size = 6
      // "totalFlag" -> "1"
      // "groupType" -> "3"
      // "varietyName" -> ""
      // "region" -> "130000"
      // "realCompanyName" -> ""
      // "crop" -> ""
      // debugger
      region.value = props.dialogPageData.regionCode
      crop.value = props.dialogPageData.crop
      if ('qiye-pz' == props.currentTab) {//企业品种
        // debugger
        //http://114.242.25.97:20167/api/seedarchive/api/getAllSeedCompanySummary
        // ?totalFlag=0&groupType=3&varietyName=&region=999999&realCompanyName=北京大北农生物技术有限公司&crop=
        totalFlag.value = 0;
        groupType.value = 3
        region.value = user.RegManageRegionID
        realCompanyName.value = props.dialogPageData.companyName
      }
    }
    if (cjRegion.value == 4) {
      //http://114.242.25.97:20167/api/seedarchive/api/getAllSeedCompanySummary?
      // totalFlag=1&groupType=3&varietyName=&region=130108&realCompanyName=&crop=
      totalFlag.value = 1;
      groupType.value = 3
      region.value = user.RegManageRegionID
    }

  }
}
const pageIndex = ref(1)
const listData = ref([])
// map = {HashMap@18579}  size = 6
// "totalFlag":"1"
// "groupType":"4"
// "varietyName":""
// "region":"999999"
// "realCompanyName":""
// "crop":""
const totalFlag = ref(1)////totalFlag：合计标志，0-不增加合计，1-在开头增加一个合计行
const groupType = ref(4)////1-按区域分组，2-按企业分组，3-按品种和企业,4=按区域分组，没数据不显示
const varietyName = ref('')//varietyName：精确的品种名称，筛选条件
const region = ref(999999)
const realCompanyName = ref('')//：精确的企业名称，筛选条件
const crop = ref('')
const cjRegion = ref(1)//1=全国，2=省，3=县，4=市
function getCjRegion() {
  if ("1" == user.UserRoleID) {//"国家"
    cjRegion.value = 1
  } else if ("2" == user.UserRoleID) {// "省"
    cjRegion.value = 2
  } else if ("3" == user.UserRoleID) {//"县"
    cjRegion.value = 4
  } else if ("4" == user.UserRoleID) {//"市"
    cjRegion.value = 3
  }
  console.log('getCjRegion=', cjRegion.value)
}

const getList = (itemData, cj) => {
  // debugger
  uiUtil.http().getObj({
    url: uiUtil.urlPath.getAllSeedCompanySummary,
    data: {
      "totalFlag": totalFlag.value,// "1",
      "groupType": groupType.value,//"4",
      "varietyName": varietyName.value,// "",
      "region": region.value,// "999999",
      "realCompanyName": realCompanyName.value,// "",
      "crop": crop.value// ""
    },
    start: function start() {
      uiUtil.toastLoading()
    },
    succeed: function succeed(res) {
      // debugger
      // debugger
      if (200 != res.code) {
        uiUtil.toastFail(res.msg)
        return
      }
      if ('quyu' == props.currentTab||'search-quyu'==props.currentTab) {
        res.data.forEach((item, index) => {
          item.cj = cj
          item.viewShow = 0
          item.arr = []
          parsValue(item)
        })
        if (listData.value.length == 0) {
          listData.value = res.data
        } else {
          itemData.arr = res.data
        }
        console.log('cj', cj)
      } else if ('qiye' == props.currentTab || 'pz' == props.currentTab || 'qiye-pz' == props.currentTab) {
        res.data.forEach((item, index) => {
          parsValue(item)
        })
        listData.value = res.data
        // console.log('aaaa')
      }
      console.log('listData=', listData.value)
    },
    failed: function failed(res) {
    },
    finish: function finish() {
      uiUtil.toastClose()
      isRefresh.value = false;
    }
  })
};

const isRefresh = ref(true);

//下拉刷新
const onRefresh = () => {
  pageIndex.value = 1;
  listData.value = [];
  region.value = user.RegManageRegionID
  totalFlag.value = 1
  if ('search-quyu' == props.currentTab) {
    getList2(null, 1)
  } else {
    getList(null, 1);
  }
};
/////////////滑动冲突////////////////////
const refreshDisabled = ref(true)
const handleScroll = (e) => {
  if (0 == event.target.scrollTop) {
    refreshDisabled.value = false
  } else {
    refreshDisabled.value = true
  }
  // console.log('event.target.scrollTop=',event.target.scrollTop,refreshDisabled.value,isRefresh.value)
}
/////////////搜索区域//////////////////////////
const regionName = ref('')
const getList2 = (itemData, cj) => {
  // debugger
  //http://114.242.25.97:20167/api/seedarchive/api/searchRegionByRegionName?
  // totalFlag=0&groupType=4&regionName=河北省&varietyName=&realCompanyName=&parentRegionCode=999999&crop=
  uiUtil.http().getObj({
    url: uiUtil.urlPath.searchRegionByRegionName,
    data: {
      "totalFlag": totalFlag.value,// "1",
      "groupType": groupType.value,//"4",
      "regionName": regionName.value,// "",
      "varietyName": varietyName.value,// "",// "999999",
      "realCompanyName": realCompanyName.value,// "",
      "parentRegionCode": region.value,
      "crop": crop.value// ""
    },
    start: function start() {
      uiUtil.toastLoading()
    },
    succeed: function succeed(res) {
      // debugger
      if (200 != res.code) {
        uiUtil.toastFail(res.msg)
        return
      }
      res.data.forEach((item, index) => {
        item.cj = cj
        item.viewShow = 0
        item.arr = []
        parsValue(item)
      })
      listData.value = res.data
      console.log('cj', cj)
      console.log('listData=', listData.value)
    },
    failed: function failed(res) {
    },
    finish: function finish() {
      uiUtil.toastClose()
      isRefresh.value = false;
    }
  })
};

/////////////////////////
function getNumberData2(value) {
  try {

    if (uiUtil.isStrNull(value)) return "0";
    if (1 != cjRegion.value) return value
    let d = parseFloat(value);
    if (d < 10) return "0";
    var isGuoJia = false
    if (user.RegionName == '国家') {
      isGuoJia = true
    } else {
      isGuoJia = false
    }
    if (isGuoJia) {
      d = d / 10000;
    }

    let bd = parseFloat(d.toFixed(2));
    let roundedNum = bd.toString();
    // console.log("四舍五入后的结果为：" + roundedNum);

    if (bd > 0) {
      return roundedNum;
    }

    let s = d.toString();
    if (s.includes(".")) {
      let s_length = s.split(".")[1];
      let sl = s_length.length;

      if (sl === 1) {
        s = s + "0";
        return s;
      } else if (sl === 2) {
        return s;
      } else if (sl >= 3) {
        let fmtstr = d.toFixed(3);
        let nstr = fmtstr.charAt(fmtstr.length - 1);
        let f = 0;

        if (nstr !== "0") {
          f = parseFloat(fmtstr) + 0.01;
        } else {
          f = parseFloat(fmtstr);
        }

        let fmtst2 = f.toString();

        if (fmtst2.split(".")[1].length === 3) {
          fmtst2 = fmtst2.slice(0, -1);
        } else if (fmtst2.split(".")[1].length > 3) {
          fmtst2 = fmtst2.slice(0, fmtst2.indexOf(".") + 3);
        }

        return fmtst2;
      }
    }

  } catch (e) {
    console.error(e);
  }
  return value;
}


function getRandomString(length) {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  const charactersLength = characters.length;
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * charactersLength));
  }
  return result;
}


</script>

<style scoped lang="less">

</style>